﻿using Server.Models;

using SuperSocket.SocketBase;
using SuperSocket.SocketBase.Config;
using SuperSocket.SocketBase.Protocol;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Server.Core.Service
{
    // 服务类
    public class NetServer : AppServer<NetSession>
    {
        #region 配置

        protected override bool Setup(IRootConfig rootConfig, IServerConfig config)
        {
            return base.Setup(rootConfig, config);
        }

        #endregion 配置

        #region 启动服务

        protected override void OnStarted()
        {
            base.OnStarted();
        }

        #endregion 启动服务

        #region 停止服务

        protected override void OnStopped()
        {
            base.OnStopped();
        }

        #endregion 停止服务
    }

    // 会话类
    public class NetSession : AppSession<NetSession>
    {
        public UserModel UserInfo;

        #region 连接成功

        protected override void OnSessionStarted()
        {
            // 发送欢迎信息
            Send("连接成功");
        }

        #endregion 连接成功

        #region 未知请求

        protected override void HandleUnknownRequest(StringRequestInfo requestInfo)
        {
            // 丢弃
        }

        #endregion 未知请求

        #region 异常

        protected override void HandleException(Exception e)
        {
            // 发回错误信息
            Send("App Error:" + e.Message);
        }

        #endregion 异常

        #region 会话关闭

        protected override void OnSessionClosed(CloseReason reason)
        {
            base.OnSessionClosed(reason);
        }

        #endregion 会话关闭
    }
}